<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
</head>
<body>
<h1>异步请求工程</h1>

<div>
    <input type="button" value="异步Get请求" @click="f1()">
    <input type="button" value="异步Post请求" @click="f2()">
    <a href="/bmi.html">BMI测试</a>
    <hr>
    <a href="/reg.html">注册</a>
    <a href="/login.html">登录</a>
</div>

<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<script>
    let v = new Vue({
        el: "body>div",
        data: {},
        methods: {
            f1() {
                //发出异步的get请求
                // axios.get("/helloAxios").then(function (response) {
                //     //response对象代表响应，里面装着服务器响应的数据response.data
                //     alert(response.data);
                // })

                //发出异步请求同时传参
                axios.get("/p1?name=tom&age=18").then(function (response) {
                    alert(response.data);
                })
            },
            f2() {
                // //发出异步的post请求
                // axios.post("/helloAxios").then(function (response) {
                //     alert(response.data);
                // })

                //发出异步请求同时传参，需要先建立实体对象，将对象装到p里面
                let p = {title: "老冰棍儿", price: 1.0, num: 1000}
                axios.post("/p2", p).then(function (response) {
                    alert(response.data);
                })
            }
        }
    })
</script>

</body>
</html>